package com.jungle.mvvm.sample.ui.detail;

import android.app.Application;
import android.databinding.ObservableBoolean;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.view.View;

import com.jungle.mvvm.base.BaseViewModel;
import com.jungle.mvvm.binding.command.BindingAction;
import com.jungle.mvvm.binding.command.BindingCommand;
import com.jungle.mvvm.sample.R;
import com.jungle.mvvm.sample.app.MyApplication;
import com.jungle.mvvm.sample.ui.toolbar.ToolBarViewModel;

/**
 * @ClassName DetailViewModel
 * @Description DetailViewModel
 * @Author Daniel
 * @Version V1.0.0
 */
public class DetailViewModel extends BaseViewModel {
    public ToolBarViewModel toolBarViewModel;
    public ObservableBoolean haveToolBar = new ObservableBoolean(true);
    //封装一个界面发生改变的观察者
    public UIChangeObservable uc = new UIChangeObservable();

    public class UIChangeObservable {
        //下拉刷新完成
        public ObservableBoolean finishRefreshing = new ObservableBoolean(false);
    }

    public DetailViewModel(@NonNull Application application) {
        super(application);
        toolBarViewModel = new ToolBarViewModel(this);
        toolBarViewModel.rightVisible.set(View.VISIBLE);
        Drawable drawable = MyApplication.getInstance().getResources().getDrawable(R.drawable.ic_refresh_white);
        toolBarViewModel.rightImg.set(drawable);
        toolBarViewModel.setRightClick(new BindingCommand(new BindingAction() {
            @Override
            public void call() {
                uc.finishRefreshing.set(!uc.finishRefreshing.get());
            }
        }));
    }

    public void init(String title) {
        toolBarViewModel.title.set(title);
    }

}
